<?php
/**
 * Created by PhpStorm.
 * User: allen.qiang
 * Date: 15-6-10
 * Time: 下午4:05
 */

class icePackCode {
    /**
     * 获取冰包标签
     */
    public function getIcePackLabel($cityID,$distributionID){

        global $G_PGLOB;

        $key = 'ice_pack_label_'.$cityID.'_'.$distributionID;

        $code = $G_PGLOB->sessionCache_get($key,true);

        if(!is_null($code)){

            $value = $code;

        }else{

            $value = 1;

            $timeout = strtotime(date('Y-m-d').' 23:59:59') - time();

            $G_PGLOB->sessionCache_set($key,$value,$timeout,true);

        }

        $label = date('Ymd').$distributionID.sprintf("%03d",$value);

        return $label;
    }

    /**
     * 更新冰包标签
     */
    public function updateIcePackLabel($cityID,$distributionID){

        global $G_PGLOB;

        $key = 'ice_pack_label_'.$cityID.'_'.$distributionID;

        $code = $G_PGLOB->sessionCache_get($key,true);

        if(!is_null($code)){

            $num = $code + 1;

        }else{

            $num = 1;

        }

        $timeout = strtotime(date('Y-m-d').' 23:59:59') - time();

        $return = $G_PGLOB->sessionCache_set($key,$num,$timeout,true);

        return $return;
    }
}